/**
 *  Copyright (c) 2010-2011, Monash e-Research Centre
 * (Monash University, Australia)
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 * * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 * * Neither the name of the Monash University nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
 /**
 * Configuration Action
 * 
 * Parameters that are configured:
 * 
 */
package au.edu.monash.its.confluence.plugins.config;

import au.edu.monash.its.confluence.plugins.FedoraPublishManager;

import com.atlassian.confluence.core.ConfluenceActionSupport;

/**
 * @author grischa
 *
 */
public class ConfigureFedoraPublishAction extends ConfluenceActionSupport
{

	
	
	/**
	 * ??? 
	 */
	private static final long serialVersionUID = 3390282642278237821L;
	
	private FedoraPublishManager fedoraPublishManager;
	private String serverURL;
	private String username;
	private String password;
	private String pdfUser;
	private String pdfPassword;
	private String publishUsers;
	

	public boolean isPermitted() {
	// Fix Permissions. Several options available, see: http://63-246-22-42.contegix.com/atlassian-confluence/3.1/com/atlassian/confluence/security/DefaultPermissionManager.html
		
		//PermissionManager myPermissionManager = new DefaultPermissionManager();
		return true;
		//return myPermissionManager.hasPermission(User,Permission,Object);
	}


	/**
	 * @param serverURL the serverURL to set
	 */
	public void setServerURL(String serverURL) {
		this.serverURL = serverURL;
	}


	/**
	 * @return the serverURL
	 */
	public String getServerURL() {
		return serverURL;
	}


	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}


	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}


	/**
	 * @param username the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}


	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param pdfUser the pdfUser to set
	 */
	public void setPdfUser(String pdfUser) {
		this.pdfUser = pdfUser;
	}


	/**
	 * @return the pdfUser
	 */
	public String getPdfUser() {
		return pdfUser;
	}


	/**
	 * @param pdfPassword the pdfPassword to set
	 */
	public void setPdfPassword(String pdfPassword) {
		this.pdfPassword = pdfPassword;
	}


	/**
	 * @return the pdfPassword
	 */
	public String getPdfPassword() {
		return pdfPassword;
	}


	/**
	 * @param publishUsers the publishUsers to set
	 */
	public void setPublishUsers(String publishUsers) {
		this.publishUsers = publishUsers;
	}


	/**
	 * @return the publishUsers
	 */
	public String getPublishUsers() {
		return publishUsers;
	}


	public String save() throws Exception {
		fedoraPublishManager.saveServerURL(this.serverURL);
		fedoraPublishManager.saveUsername(this.username);
		fedoraPublishManager.savePassword(this.password);
		fedoraPublishManager.savePDFUser(this.pdfUser);
		fedoraPublishManager.savePDFPassword(this.pdfPassword);
		fedoraPublishManager.savePublishUsers(this.publishUsers);
		addActionMessage(getText("successfully.saved.details"));
		return SUCCESS;
	}

	public String input() {
		this.serverURL = fedoraPublishManager.getServerURL();
		this.username = fedoraPublishManager.getUsername();
		this.password = fedoraPublishManager.getPassword();
		this.pdfUser = fedoraPublishManager.getPDFUser();
		this.pdfPassword = fedoraPublishManager.getPDFPassword();
		this.publishUsers = fedoraPublishManager.getPublishUsers();
		return INPUT;
	}

//	public String add() {
//		fedoraPublishManager.saveServerURL(this.serverURL);
//		fedoraPublishManager.saveUsername(this.username);
//		fedoraPublishManager.savePassword(this.password);
//		return SUCCESS;
//	}

	public String delete() {
		fedoraPublishManager.saveServerURL(null);
		fedoraPublishManager.saveUsername(null);
		fedoraPublishManager.savePassword(null);
		fedoraPublishManager.savePDFUser(null);
		fedoraPublishManager.savePDFPassword(null);
		fedoraPublishManager.savePublishUsers(null);
		return SUCCESS;
	}


	/**
	 * @param fedoraPublishManager the fedoraPublishManager to set
	 */
	public void setFedoraPublishManager(FedoraPublishManager fedoraPublishManager) {
		this.fedoraPublishManager = fedoraPublishManager;
	}


}
